Push Notifications
Resources
- client-server spec for push notification related endpoints
- push gateway spec
- the reference implementation, sygnal
- ansible script docs on deploying sygnal
- notes for application developers from the sygnal team
- describes the relationship btw the push server and the application
- how the server decides when to send a push
- how the homeserver is made aware of the push server
FCM For Android notifications (and potentially iOS)
- add firebase to the app
- add firebase to your flutter app
- I moved the
google-services.json
into the staging flavour and corrected it's package - only the staging flavour currently initializes firebase
- add FCM to the flutter project
How fluffychat does it
- they primarly use unifiedPush
- they have a patch in the codebase that can be applied to activate Firebase in case they don't want to use UnifiedPush
- this does not use the flutter Firebase package. It configures it in the native apps (including the
google-services.json
and including the native firebase library) and then uses a custom built fcm_shared_isolates flutter library to interact with native firebase library (fetch fcm tokens, etc.)
- this does not use the flutter Firebase package. It configures it in the native apps (including the
- the backgroundPush class handles the relationship with FCM and is assocaited with the root Matrix widget but doesn't do much other than raise errors via dialogs and unsubscribe from onSync when the widget gets displosed.
How we will do it
- probably just follow google docs RE firebase on flutter (use the flutter firebase package/CLI)
- Unified push is a more general purpose solution (works on devices without google services) and doesn't send push messages through google servers
- but I don't have the resources for that right now
- convert the BackgroundPush class to a singleton service with GetIt?
- figure out how much of background push we actually need
- need to add the POST_NOTIFICATION android permission these days apparently
- investigating the merged AndroidManifest, it appears that the firebase messaging libraries add the POST_NOTIFICATION android permission
- now how do we ask for the permission?
- there is a popular
permission_handler
library - fluffychat has the dependency but it looks like they only use for their windows build?
- here are the android docs regarding how to request permissions
- there is a popular
Configuring the Sygnal Push gateway
- add the configuration to enable sygnal for fcm
- refer to sygnal defaults file for ansible sygnal deployment configuration options
- refer to the sygnal sample yaml for sygnal server configurations
- need to use the service_account_file option (looks like api_key is deprecated)
- create a service account and a service account file
- firebase > settings > Cloud Messaging > Manage service accounts
- I am using the existing firebase service account for quiri-staging
- manage keys > add key > json
- create an
aux_file_definition
for the service account file like they demonstrate for the APNS key- you paste the file contents right into the playbook configuration
- there are no
matrix_user_name
ormatrix_group_name
defined as variables so I just hardcodedmatrix
for both as the docs sayIt also makes sure the files are owned by matrix:matrix, so that Sygnal can read them.
- add the sygnal dns record
Test pushes
- use postman to login as a user
- add a new pusher for the user
- pointing to the sygnal gateway
- add a push rule for that user
if no rules match an event, the homeserver MUST NOT notify the Push Gateway.
- actually if query the push rulesets there are a bunch or default push rules
- troubleshoot by trying to send request direct to the push gateway with postman
- open a shell via DigitalOcean console and
journalctl -fu matrix-sygnal.service
to inspect gateway logs
- open a shell via DigitalOcean console and
Trobuleshooting
- sygnal.gcmpushkin log
- sygnal.access log
- this should only be after
event_id_only
- Currently the only format available is
event_id_only'
- When the homeserver is performing a push where the format is "event_id_only", only the event_id, room_id, counts, and devices are required to be populated.
- sygnal README with configuration details
- event_id_only is recommended for privacy
- but no alternative is offered. Maybe
Open Questions
- how are environments handled in Firebase projects?
- readme
- make a new project for each environment